//
//  KXNetworkStatusService.m
//  JPVideoPlayerDemo
//
//  Created by xin on 2018/4/20.
//  Copyright © 2018年 NewPan. All rights reserved.
//

#import "KXNetworkStatusService.h"
#import "AFNetworkReachabilityManager.h"
#import "Reachability.h"

@implementation KXNetworkStatusService

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(nullable NSDictionary *)launchOptions
{
    NSLog(@"%@ didFinishLaunchingWithOptions",NSStringFromClass([self class]));
    
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
    
        NSString *remoteHostName = @"www.bing.com";
        Reachability *hostReachability = [Reachability reachabilityWithHostName:remoteHostName];
        [hostReachability startNotifier];
        
        Reachability *routerReachability   = [Reachability reachabilityForInternetConnection];
        [routerReachability startNotifier];
        // 开启当前线程消息循环
        [[NSRunLoop currentRunLoop] run];
    });
    
    [[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        switch (status) {
            case AFNetworkReachabilityStatusNotReachable:
                NSLog(@"AFNetworkReachability Not Reachable");
                break;
            case AFNetworkReachabilityStatusReachableViaWWAN:
                NSLog(@"AFNetworkReachability Reachable via WWAN");
                break;
            case AFNetworkReachabilityStatusReachableViaWiFi:
                NSLog(@"AFNetworkReachability Reachable via WiFi");
                break;
            case AFNetworkReachabilityStatusUnknown:
            default:
                NSLog(@"AFNetworkReachability Unknown");
                break;
        }
    }];
    [[AFNetworkReachabilityManager sharedManager] startMonitoring];
    
    return YES;
}

@end
